//
//  AuctionRecordView.m
//  phmall
//
//  Created by admin on 2017/12/4.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "AuctionRecordView.h"
#import "AuctionRecordViewCell.h"
@implementation AuctionRecordView

-(instancetype)init{
    if (self=[super init]) {
        self.head=[[UIView alloc]init];
        self.head.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.head];
        
        self.title=[[UILabel alloc]init];
        self.title.text=@"竞拍记录";
        self.title.font=[UIFont systemFontOfSize:17];
        [self.head addSubview:self.title];
        
        self.more=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.head addSubview:self.more];
        [self.more setTitle:[NSString stringWithFormat:@"%@>",Localized(@"更多")] forState:UIControlStateNormal];
        [self.more setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        self.more.titleLabel.font=[UIFont systemFontOfSize:12];
        [self.more setImage:[UIImage imageNamed:[NSString stringWithFormat:@"back"]] forState:UIControlStateNormal];
        [self.more addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:self.myTableview];
        self.myTableview.scrollEnabled =NO;
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.head mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(44);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.offset(0);
    }];
    
    [self.more mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
    }];
    
    [self.myTableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.head.mas_bottom).offset(0);
        make.left.right.equalTo(self).priorityHigh();
        make.bottom.equalTo(self);
    }];
}
// Do any additional setup after loading the view.

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AuctionRecordViewCell *cell=[AuctionRecordViewCell theShareCellWithTableView:tableView];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(self.delegate&&[self.delegate respondsToSelector:@selector(checkAuctionRecordDetails)]) {
        [self.delegate checkAuctionRecordDetails];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    //分割线补全
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

//MARK:-GETTER
- (UITableView *)myTableview{
    if (!_myTableview) {
        _myTableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableview.delegate = self;
        _myTableview.dataSource = self;
        _myTableview.backgroundColor=[UIColor whiteColor];
        _myTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableview.showsVerticalScrollIndicator=NO;
        _myTableview.scrollEnabled = YES;
    }
    return _myTableview;
}
-(void)moreAction{
    if(self.delegate&&[self.delegate respondsToSelector:@selector(checkAuctionRecordDetails)]) {
        [self.delegate checkAuctionRecordDetails];
    }
}
@end
